#ifndef _UTILS_NET_H_
#define _UTILS_NET_H_

#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#include <net/if.h>
#include <netinet/in.h>

    typedef struct utils_ipv4_info
    {
        uint8_t dhcp;
        char addr[INET_ADDRSTRLEN];
        char mask[INET_ADDRSTRLEN];
        char gateway[INET_ADDRSTRLEN];
    } utils_ipv4_info;

    typedef struct utils_ipv6_info
    {
        uint8_t dhcp;
        char addr[INET6_ADDRSTRLEN];
        char mask[INET6_ADDRSTRLEN];
        char gateway[INET6_ADDRSTRLEN];
    } utils_ipv6_info;

    typedef struct utils_if_info
    {
        uint8_t if_idx;
        uint8_t duplex;
        uint32_t speed;
        char if_mac[18];
        unsigned char if_mac_hex[8];
        char if_name[IF_NAMESIZE];
        utils_ipv4_info ipv4;
        utils_ipv6_info ipv6;
    } utils_if_info;

    /**
     * @brief Get NIC info by NIC name
     *
     * @param if_name [in] nic name
     * @return utils_if_info
     */
    extern utils_if_info utils_net_if_info(const char *if_name);
    /**
     * @brief Get NIC info by specify IP
     *
     * @param compare_ip_addr [in] IP
     * @return utils_if_info
     */
    extern utils_if_info utils_net_if_info_by_local_ip(in_addr_t compare_ip_addr);

    /**
     * @brief check net available
     *
     * @param site [in] a domain, default qq.com
     * @param port [in] the doamin port, default 80
     * @param read_data [in] bool , 0 mean not read data, other mean read.
     * @param timeout_sec [in] timeout, unit seconds, default 10;
     * @return uint8_t 0 is unavailable, 1 is available
     */
    extern uint8_t utils_net_available(const char *site, uint16_t port, uint8_t read_data, uint8_t timeout_sec);

#ifdef __cplusplus
}
#endif
#endif //_UTILS_NET_H_